<?php

require_once BASE_PATH.'application/models/basedao'.EXT;
class emailDAO extends baseDAO {
	
	function __construct()
	{
            
	    // Call the Model constructor
	    parent::__construct();
		
	}
	
	/*function email($data){
		
		$config = array(
            'protocol' => 'sendmail',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => '465',
            'smtp_user' => 'my.pregnancy.team@gmail.com',
            'smtp_pass' => 'Embarazada100%',
            'charset' => 'iso-8859-1',
			'mailtype' => 'html',
            'wordwrap' => TRUE,
			'priority' => '1'
        );
		$this->load->library('email', $config);
		$this->email->set_newline("\r\n");
		
		$this->email->from($data['fromEmail'], $data['fromName']);
		$this->email->to($data['toEmail']);
		
		if(!empty($data['ccEmail']))
			$this->email->cc($data['ccEmail']);
		
		if(!empty($data['bccEmail']))
			$this->email->bcc($data['bccEmail']);
		
		$this->email->subject($data['subject']);
		$this->email->message($data['message']);
		if($this->email->send()){
			return TRUE;
		} else{
			show_error($this->email->print_debugger());
			return FALSE;
		}

	}*/
	function email($data){
		$email = $data['toEmail'];
		$asunto = $data['subject'];
		$cabeceras = 	'From:'. $data['fromEmail'] . "\r\n" .
				'Content-type: text/html' . "\r\n";
		
		if(mail($email,$asunto,$data['message'],$cabeceras)){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	function getForgotMessage($hash) {
		$message = 	'
		<!DOCTYPE html>
		<html>
			<head>
				<title></title>
			</head>
			<body>
				<p>Dear MyPregnancy user,
				
				You recently asked to reset your MyPregnancy password.
				Click here to change your password.
				
				<a href="http://www.deployit.com.mx/MiEmbarazo/Portal/restablecer.html">Here</a>
				Then, enter the following password reset code:
				
				'. $hash .'
				
				<p>If clicking the link above does not work, copy and paste the URL in a new browser window instead.
				If you don not click the link, the password of your account will not be reseted.</p>
				
				<p>Did not request this change?
				If you did not request a new password, let us know immediately.</p>
				
				<p>The MyPregnancy Account Team.</p>
			</body>
		</html>
		';
		
		return $message;
		
	}
	function getEmergencyEmailContent($sender,$latitud,$longitud) {
		$message = 	'
		<!DOCTYPE html>
		<html>
			<head>
				<title></title>
			</head>
		
			<body>
				<p>Hello, we are MyPregnancy Team.</p>
				
				<p>We have contacted you because '.$sender.' has sent you an alert through MyPregnancy email service.
				She might be having an emergency right now, so we strongly suggest you to contact her as soon as possible.</p>
				
				<p>She is located here:</p>
				
				<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=14&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:P%7C'.$latitud.','.$longitud.'&sensor=false"/>
				<p>Regards, MyPregnancy Team.</p>
			</body>
		</html>
		';
		
		return $message;
		
	}
	
}

?>